<!DOCTYPE html>
<!-- saved from url=(0063)http://www.axios-js.com/zh-cn/docs/#%E6%8B%A6%E6%88%AA%E5%99%A8 -->
<html lang="zh-cn"><head prefix="og: http://ogp.me/ns#"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  
  <title>axios中文文档|axios中文网 | axios</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Canonical links -->
  <link rel="canonical" href="http://axios-js.com/zh-cn/docs/index.html">
  <!-- Alternative links -->
  
    
      <link rel="alternative" hreflang="en" href="http://axios-js.com/docs/index.html">
    
      <link rel="alternative" hreflang="zh-cn" href="http://axios-js.com/zh-cn/docs/index.html">
    
  
  <!-- Icon -->
  <link rel="apple-touch-icon" sizes="57x57" href="http://www.axios-js.com/icon/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="114x114" href="http://www.axios-js.com/icon/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="72x72" href="http://www.axios-js.com/icon/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="144x144" href="http://www.axios-js.com/icon/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="60x60" href="http://www.axios-js.com/icon/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="120x120" href="http://www.axios-js.com/icon/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="76x76" href="http://www.axios-js.com/icon/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="152x152" href="http://www.axios-js.com/icon/apple-touch-icon-152x152.png">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-196x196.png" sizes="196x196">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-160x160.png" sizes="160x160">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-16x16.png" sizes="16x16">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-32x32.png" sizes="32x32">
  <meta name="msapplication-TileColor" content="#2f83cd">
  <meta name="msapplication-TileImage" content="/icon/mstile-144x144.png">
  <meta name="generator" content="Hexo 4.1.0">
  <!-- CSS -->
  <!-- build:css build/css/navy.css -->
  
<link rel="stylesheet" href="./axios中文文档_axios中文网 _ axios_files/navy.css">

  <!-- endbuild -->
  <link href="./axios中文文档_axios中文网 _ axios_files/css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="./axios中文文档_axios中文网 _ axios_files/font-awesome.min.css">
  <link rel="stylesheet" href="./axios中文文档_axios中文网 _ axios_files/docsearch.min.css">
  <link rel="stylesheet" href="./axios中文文档_axios中文网 _ axios_files/magnific-popup.min.css">
  <!-- RSS -->
  <link rel="alternate" href="http://www.axios-js.com/atom.xml" title="axios">
  <!-- Open Graph -->
  <meta name="description" content="欢迎使用 axios，本文档将帮助您快速上手。(troubleshooting.html) 中的解答， 什么是 axios？Axios 是一个基于 promise 的 HTTP 库，可以用在浏览器和 node.js 中。 axios Axios 是一个基于 promise 的 HTTP 库，可以用在浏览器和 node.js 中。  特性 从浏览器中创建 XMLHttpRequests 从 node">
<meta property="og:type" content="website">
<meta property="og:title" content="axios中文文档|axios中文网">
<meta property="og:url" content="http://axios-js.com/zh-cn/docs/index.html">
<meta property="og:site_name" content="axios">
<meta property="og:description" content="欢迎使用 axios，本文档将帮助您快速上手。(troubleshooting.html) 中的解答， 什么是 axios？Axios 是一个基于 promise 的 HTTP 库，可以用在浏览器和 node.js 中。 axios Axios 是一个基于 promise 的 HTTP 库，可以用在浏览器和 node.js 中。  特性 从浏览器中创建 XMLHttpRequests 从 node">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img.shields.io/npm/v/axios.svg?style=flat-square">
<meta property="og:image" content="https://img.shields.io/travis/axios/axios.svg?style=flat-square">
<meta property="og:image" content="https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square">
<meta property="og:image" content="https://img.shields.io/npm/dm/axios.svg?style=flat-square">
<meta property="og:image" content="https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square">
<meta property="og:image" content="https://www.codetriage.com/axios/axios/badges/users.svg">
<meta property="og:image" content="https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png">
<meta property="og:image" content="https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png">
<meta property="og:image" content="https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png">
<meta property="og:image" content="https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png">
<meta property="og:image" content="https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png">
<meta property="og:image" content="https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png">
<meta property="og:image" content="https://saucelabs.com/open_sauce/build_matrix/axios.svg">
<meta property="og:image" content="https://res.cloudinary.com/dq9x329zv/image/upload/v1589976054/youdontknowjs_rrotmn.jpg">
<meta property="og:image" content="https://res.cloudinary.com/dq9x329zv/image/upload/v1591535902/axios-js.com/69173465-4b00-4f42-ab61-f73891a130b4.jpg">
<meta property="og:image" content="http://axios-js.com/icon/les01.jpeg">
<meta property="og:image" content="http://axios-js.com/icon/les02.jpeg">
<meta property="og:image" content="http://axios-js.com/icon/les03.jpeg">
<meta property="og:image" content="http://axios-js.com/icon/les04.jpeg">
<meta property="article:published_time" content="2021-05-30T01:01:16.000Z">
<meta property="article:modified_time" content="2021-05-30T01:01:16.000Z">
<meta property="article:author" content="Hexo">
<meta property="article:tag" content="axios中文文档">
<meta property="article:tag" content=" axios API中文">
<meta property="article:tag" content=" axios 跨域请求">
<meta property="article:tag" content=" axios post">
<meta property="article:tag" content=" axios get">
<meta property="article:tag" content=" axios 配置">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img.shields.io/npm/v/axios.svg?style=flat-square">
  <!-- Analytics -->
  
<script>
    (function(h,o,t,j,a,r){
        h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
        h._hjSettings={hjid:1120304,hjsv:6};
        a=o.getElementsByTagName('head')[0];
        r=o.createElement('script');r.async=1;
        r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
        a.appendChild(r);
    })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script><script async="" src="./axios中文文档_axios中文网 _ axios_files/hotjar-1120304.js.下载"></script>

<style>@charset "UTF-8";@-webkit-keyframes swal2-show{0%{-webkit-transform:scale(.7);transform:scale(.7)}45%{-webkit-transform:scale(1.05);transform:scale(1.05)}80%{-webkit-transform:scale(.95);transform:scale(.95)}100%{-webkit-transform:scale(1);transform:scale(1)}}@keyframes swal2-show{0%{-webkit-transform:scale(.7);transform:scale(.7)}45%{-webkit-transform:scale(1.05);transform:scale(1.05)}80%{-webkit-transform:scale(.95);transform:scale(.95)}100%{-webkit-transform:scale(1);transform:scale(1)}}@-webkit-keyframes swal2-hide{0%{-webkit-transform:scale(1);transform:scale(1);opacity:1}100%{-webkit-transform:scale(.5);transform:scale(.5);opacity:0}}@keyframes swal2-hide{0%{-webkit-transform:scale(1);transform:scale(1);opacity:1}100%{-webkit-transform:scale(.5);transform:scale(.5);opacity:0}}@-webkit-keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.875em;width:1.5625em}}@keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.875em;width:1.5625em}}@-webkit-keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@-webkit-keyframes swal2-rotate-success-circular-line{0%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}5%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}12%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}100%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}}@keyframes swal2-rotate-success-circular-line{0%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}5%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}12%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}100%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}}@-webkit-keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;-webkit-transform:scale(.4);transform:scale(.4);opacity:0}50%{margin-top:1.625em;-webkit-transform:scale(.4);transform:scale(.4);opacity:0}80%{margin-top:-.375em;-webkit-transform:scale(1.15);transform:scale(1.15)}100%{margin-top:0;-webkit-transform:scale(1);transform:scale(1);opacity:1}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;-webkit-transform:scale(.4);transform:scale(.4);opacity:0}50%{margin-top:1.625em;-webkit-transform:scale(.4);transform:scale(.4);opacity:0}80%{margin-top:-.375em;-webkit-transform:scale(1.15);transform:scale(1.15)}100%{margin-top:0;-webkit-transform:scale(1);transform:scale(1);opacity:1}}@-webkit-keyframes swal2-animate-error-icon{0%{-webkit-transform:rotateX(100deg);transform:rotateX(100deg);opacity:0}100%{-webkit-transform:rotateX(0);transform:rotateX(0);opacity:1}}@keyframes swal2-animate-error-icon{0%{-webkit-transform:rotateX(100deg);transform:rotateX(100deg);opacity:0}100%{-webkit-transform:rotateX(0);transform:rotateX(0);opacity:1}}body.swal2-toast-shown .swal2-container{background-color:transparent}body.swal2-toast-shown .swal2-container.swal2-shown{background-color:transparent}body.swal2-toast-shown .swal2-container.swal2-top{top:0;right:auto;bottom:auto;left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{top:0;right:0;bottom:auto;left:auto}body.swal2-toast-shown .swal2-container.swal2-top-left,body.swal2-toast-shown .swal2-container.swal2-top-start{top:0;right:auto;bottom:auto;left:0}body.swal2-toast-shown .swal2-container.swal2-center-left,body.swal2-toast-shown .swal2-container.swal2-center-start{top:50%;right:auto;bottom:auto;left:0;-webkit-transform:translateY(-50%);transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{top:50%;right:auto;bottom:auto;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{top:50%;right:0;bottom:auto;left:auto;-webkit-transform:translateY(-50%);transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-left,body.swal2-toast-shown .swal2-container.swal2-bottom-start{top:auto;right:auto;bottom:0;left:0}body.swal2-toast-shown .swal2-container.swal2-bottom{top:auto;right:auto;bottom:0;left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{top:auto;right:0;bottom:0;left:auto}body.swal2-toast-column .swal2-toast{flex-direction:column;align-items:stretch}body.swal2-toast-column .swal2-toast .swal2-actions{flex:1;align-self:stretch;height:2.2em;margin-top:.3125em}body.swal2-toast-column .swal2-toast .swal2-loading{justify-content:center}body.swal2-toast-column .swal2-toast .swal2-input{height:2em;margin:.3125em auto;font-size:1em}body.swal2-toast-column .swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast{flex-direction:row;align-items:center;width:auto;padding:.625em;overflow-y:hidden;box-shadow:0 0 .625em #d9d9d9}.swal2-popup.swal2-toast .swal2-header{flex-direction:row}.swal2-popup.swal2-toast .swal2-title{flex-grow:1;justify-content:flex-start;margin:0 .6em;font-size:1em}.swal2-popup.swal2-toast .swal2-footer{margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-popup.swal2-toast .swal2-close{position:static;width:.8em;height:.8em;line-height:.8}.swal2-popup.swal2-toast .swal2-content{justify-content:flex-start;font-size:1em}.swal2-popup.swal2-toast .swal2-icon{width:2em;min-width:2em;height:2em;margin:0}.swal2-popup.swal2-toast .swal2-icon::before{display:flex;align-items:center;font-size:2em;font-weight:700}@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){.swal2-popup.swal2-toast .swal2-icon::before{font-size:.25em}}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{flex-basis:auto!important;height:auto;margin:0 .3125em}.swal2-popup.swal2-toast .swal2-styled{margin:0 .3125em;padding:.3125em .625em;font-size:1em}.swal2-popup.swal2-toast .swal2-styled:focus{box-shadow:0 0 0 .0625em #fff,0 0 0 .125em rgba(50,100,150,.4)}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;-webkit-transform:rotate(45deg);transform:rotate(45deg);border-radius:50%}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-.8em;left:-.5em;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:2em 2em;transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-.25em;left:.9375em;-webkit-transform-origin:0 1.5em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}.swal2-popup.swal2-toast.swal2-show{-webkit-animation:swal2-toast-show .5s;animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{-webkit-animation:swal2-toast-hide .1s forwards;animation:swal2-toast-hide .1s forwards}.swal2-popup.swal2-toast .swal2-animate-success-icon .swal2-success-line-tip{-webkit-animation:swal2-toast-animate-success-line-tip .75s;animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-animate-success-icon .swal2-success-line-long{-webkit-animation:swal2-toast-animate-success-line-long .75s;animation:swal2-toast-animate-success-line-long .75s}@-webkit-keyframes swal2-toast-show{0%{-webkit-transform:translateY(-.625em) rotateZ(2deg);transform:translateY(-.625em) rotateZ(2deg)}33%{-webkit-transform:translateY(0) rotateZ(-2deg);transform:translateY(0) rotateZ(-2deg)}66%{-webkit-transform:translateY(.3125em) rotateZ(2deg);transform:translateY(.3125em) rotateZ(2deg)}100%{-webkit-transform:translateY(0) rotateZ(0);transform:translateY(0) rotateZ(0)}}@keyframes swal2-toast-show{0%{-webkit-transform:translateY(-.625em) rotateZ(2deg);transform:translateY(-.625em) rotateZ(2deg)}33%{-webkit-transform:translateY(0) rotateZ(-2deg);transform:translateY(0) rotateZ(-2deg)}66%{-webkit-transform:translateY(.3125em) rotateZ(2deg);transform:translateY(.3125em) rotateZ(2deg)}100%{-webkit-transform:translateY(0) rotateZ(0);transform:translateY(0) rotateZ(0)}}@-webkit-keyframes swal2-toast-hide{100%{-webkit-transform:rotateZ(1deg);transform:rotateZ(1deg);opacity:0}}@keyframes swal2-toast-hide{100%{-webkit-transform:rotateZ(1deg);transform:rotateZ(1deg);opacity:0}}@-webkit-keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@-webkit-keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}@keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto!important}body.swal2-no-backdrop .swal2-shown{top:auto;right:auto;bottom:auto;left:auto;max-width:calc(100% - .625em * 2);background-color:transparent}body.swal2-no-backdrop .swal2-shown>.swal2-modal{box-shadow:0 0 10px rgba(0,0,0,.4)}body.swal2-no-backdrop .swal2-shown.swal2-top{top:0;left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%)}body.swal2-no-backdrop .swal2-shown.swal2-top-left,body.swal2-no-backdrop .swal2-shown.swal2-top-start{top:0;left:0}body.swal2-no-backdrop .swal2-shown.swal2-top-end,body.swal2-no-backdrop .swal2-shown.swal2-top-right{top:0;right:0}body.swal2-no-backdrop .swal2-shown.swal2-center{top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)}body.swal2-no-backdrop .swal2-shown.swal2-center-left,body.swal2-no-backdrop .swal2-shown.swal2-center-start{top:50%;left:0;-webkit-transform:translateY(-50%);transform:translateY(-50%)}body.swal2-no-backdrop .swal2-shown.swal2-center-end,body.swal2-no-backdrop .swal2-shown.swal2-center-right{top:50%;right:0;-webkit-transform:translateY(-50%);transform:translateY(-50%)}body.swal2-no-backdrop .swal2-shown.swal2-bottom{bottom:0;left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%)}body.swal2-no-backdrop .swal2-shown.swal2-bottom-left,body.swal2-no-backdrop .swal2-shown.swal2-bottom-start{bottom:0;left:0}body.swal2-no-backdrop .swal2-shown.swal2-bottom-end,body.swal2-no-backdrop .swal2-shown.swal2-bottom-right{right:0;bottom:0}.swal2-container{display:flex;position:fixed;z-index:1060;top:0;right:0;bottom:0;left:0;flex-direction:row;align-items:center;justify-content:center;padding:.625em;overflow-x:hidden;background-color:transparent;-webkit-overflow-scrolling:touch}.swal2-container.swal2-top{align-items:flex-start}.swal2-container.swal2-top-left,.swal2-container.swal2-top-start{align-items:flex-start;justify-content:flex-start}.swal2-container.swal2-top-end,.swal2-container.swal2-top-right{align-items:flex-start;justify-content:flex-end}.swal2-container.swal2-center{align-items:center}.swal2-container.swal2-center-left,.swal2-container.swal2-center-start{align-items:center;justify-content:flex-start}.swal2-container.swal2-center-end,.swal2-container.swal2-center-right{align-items:center;justify-content:flex-end}.swal2-container.swal2-bottom{align-items:flex-end}.swal2-container.swal2-bottom-left,.swal2-container.swal2-bottom-start{align-items:flex-end;justify-content:flex-start}.swal2-container.swal2-bottom-end,.swal2-container.swal2-bottom-right{align-items:flex-end;justify-content:flex-end}.swal2-container.swal2-bottom-end>:first-child,.swal2-container.swal2-bottom-left>:first-child,.swal2-container.swal2-bottom-right>:first-child,.swal2-container.swal2-bottom-start>:first-child,.swal2-container.swal2-bottom>:first-child{margin-top:auto}.swal2-container.swal2-grow-fullscreen>.swal2-modal{display:flex!important;flex:1;align-self:stretch;justify-content:center}.swal2-container.swal2-grow-row>.swal2-modal{display:flex!important;flex:1;align-content:center;justify-content:center}.swal2-container.swal2-grow-column{flex:1;flex-direction:column}.swal2-container.swal2-grow-column.swal2-bottom,.swal2-container.swal2-grow-column.swal2-center,.swal2-container.swal2-grow-column.swal2-top{align-items:center}.swal2-container.swal2-grow-column.swal2-bottom-left,.swal2-container.swal2-grow-column.swal2-bottom-start,.swal2-container.swal2-grow-column.swal2-center-left,.swal2-container.swal2-grow-column.swal2-center-start,.swal2-container.swal2-grow-column.swal2-top-left,.swal2-container.swal2-grow-column.swal2-top-start{align-items:flex-start}.swal2-container.swal2-grow-column.swal2-bottom-end,.swal2-container.swal2-grow-column.swal2-bottom-right,.swal2-container.swal2-grow-column.swal2-center-end,.swal2-container.swal2-grow-column.swal2-center-right,.swal2-container.swal2-grow-column.swal2-top-end,.swal2-container.swal2-grow-column.swal2-top-right{align-items:flex-end}.swal2-container.swal2-grow-column>.swal2-modal{display:flex!important;flex:1;align-content:center;justify-content:center}.swal2-container:not(.swal2-top):not(.swal2-top-start):not(.swal2-top-end):not(.swal2-top-left):not(.swal2-top-right):not(.swal2-center-start):not(.swal2-center-end):not(.swal2-center-left):not(.swal2-center-right):not(.swal2-bottom):not(.swal2-bottom-start):not(.swal2-bottom-end):not(.swal2-bottom-left):not(.swal2-bottom-right):not(.swal2-grow-fullscreen)>.swal2-modal{margin:auto}@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){.swal2-container .swal2-modal{margin:0!important}}.swal2-container.swal2-fade{transition:background-color .1s}.swal2-container.swal2-shown{background-color:rgba(0,0,0,.4)}.swal2-popup{display:none;position:relative;box-sizing:border-box;flex-direction:column;justify-content:center;width:32em;max-width:100%;padding:1.25em;border:none;border-radius:.3125em;background:#fff;font-family:inherit;font-size:1rem}.swal2-popup:focus{outline:0}.swal2-popup.swal2-loading{overflow-y:hidden}.swal2-header{display:flex;flex-direction:column;align-items:center}.swal2-title{position:relative;max-width:100%;margin:0 0 .4em;padding:0;color:#595959;font-size:1.875em;font-weight:600;text-align:center;text-transform:none;word-wrap:break-word}.swal2-actions{z-index:1;flex-wrap:wrap;align-items:center;justify-content:center;width:100%;margin:1.25em auto 0}.swal2-actions:not(.swal2-loading) .swal2-styled[disabled]{opacity:.4}.swal2-actions:not(.swal2-loading) .swal2-styled:hover{background-image:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.1))}.swal2-actions:not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0,0,0,.2),rgba(0,0,0,.2))}.swal2-actions.swal2-loading .swal2-styled.swal2-confirm{box-sizing:border-box;width:2.5em;height:2.5em;margin:.46875em;padding:0;-webkit-animation:swal2-rotate-loading 1.5s linear 0s infinite normal;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border:.25em solid transparent;border-radius:100%;border-color:transparent;background-color:transparent!important;color:transparent;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.swal2-actions.swal2-loading .swal2-styled.swal2-cancel{margin-right:30px;margin-left:30px}.swal2-actions.swal2-loading :not(.swal2-styled).swal2-confirm::after{content:"";display:inline-block;width:15px;height:15px;margin-left:5px;-webkit-animation:swal2-rotate-loading 1.5s linear 0s infinite normal;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border:3px solid #999;border-radius:50%;border-right-color:transparent;box-shadow:1px 1px 1px #fff}.swal2-styled{margin:.3125em;padding:.625em 2em;box-shadow:none;font-weight:500}.swal2-styled:not([disabled]){cursor:pointer}.swal2-styled.swal2-confirm{border:0;border-radius:.25em;background:initial;background-color:#3085d6;color:#fff;font-size:1.0625em}.swal2-styled.swal2-cancel{border:0;border-radius:.25em;background:initial;background-color:#aaa;color:#fff;font-size:1.0625em}.swal2-styled:focus{outline:0;box-shadow:0 0 0 2px #fff,0 0 0 4px rgba(50,100,150,.4)}.swal2-styled::-moz-focus-inner{border:0}.swal2-footer{justify-content:center;margin:1.25em 0 0;padding:1em 0 0;border-top:1px solid #eee;color:#545454;font-size:1em}.swal2-image{max-width:100%;margin:1.25em auto}.swal2-close{position:absolute;top:0;right:0;justify-content:center;width:1.2em;height:1.2em;padding:0;overflow:hidden;transition:color .1s ease-out;border:none;border-radius:0;outline:initial;background:0 0;color:#ccc;font-family:serif;font-size:2.5em;line-height:1.2;cursor:pointer}.swal2-close:hover{-webkit-transform:none;transform:none;background:0 0;color:#f27474}.swal2-content{z-index:1;justify-content:center;margin:0;padding:0;color:#545454;font-size:1.125em;font-weight:300;line-height:normal;word-wrap:break-word}#swal2-content{text-align:center}.swal2-checkbox,.swal2-file,.swal2-input,.swal2-radio,.swal2-select,.swal2-textarea{margin:1em auto}.swal2-file,.swal2-input,.swal2-textarea{box-sizing:border-box;width:100%;transition:border-color .3s,box-shadow .3s;border:1px solid #d9d9d9;border-radius:.1875em;background:inherit;box-shadow:inset 0 1px 1px rgba(0,0,0,.06);color:inherit;font-size:1.125em}.swal2-file.swal2-inputerror,.swal2-input.swal2-inputerror,.swal2-textarea.swal2-inputerror{border-color:#f27474!important;box-shadow:0 0 2px #f27474!important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{border:1px solid #b4dbed;outline:0;box-shadow:0 0 3px #c4e6f5}.swal2-file::-webkit-input-placeholder,.swal2-input::-webkit-input-placeholder,.swal2-textarea::-webkit-input-placeholder{color:#ccc}.swal2-file::-moz-placeholder,.swal2-input::-moz-placeholder,.swal2-textarea::-moz-placeholder{color:#ccc}.swal2-file:-ms-input-placeholder,.swal2-input:-ms-input-placeholder,.swal2-textarea:-ms-input-placeholder{color:#ccc}.swal2-file::-ms-input-placeholder,.swal2-input::-ms-input-placeholder,.swal2-textarea::-ms-input-placeholder{color:#ccc}.swal2-file::placeholder,.swal2-input::placeholder,.swal2-textarea::placeholder{color:#ccc}.swal2-range{margin:1em auto;background:inherit}.swal2-range input{width:80%}.swal2-range output{width:20%;color:inherit;font-weight:600;text-align:center}.swal2-range input,.swal2-range output{height:2.625em;padding:0;font-size:1.125em;line-height:2.625em}.swal2-input{height:2.625em;padding:0 .75em}.swal2-input[type=number]{max-width:10em}.swal2-file{background:inherit;font-size:1.125em}.swal2-textarea{height:6.75em;padding:.75em}.swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:inherit;color:inherit;font-size:1.125em}.swal2-checkbox,.swal2-radio{align-items:center;justify-content:center;background:inherit;color:inherit}.swal2-checkbox label,.swal2-radio label{margin:0 .6em;font-size:1.125em}.swal2-checkbox input,.swal2-radio input{margin:0 .4em}.swal2-validation-message{display:none;align-items:center;justify-content:center;padding:.625em;overflow:hidden;background:#f0f0f0;color:#666;font-size:1em;font-weight:300}.swal2-validation-message::before{content:"!";display:inline-block;width:1.5em;min-width:1.5em;height:1.5em;margin:0 .625em;zoom:normal;border-radius:50%;background-color:#f27474;color:#fff;font-weight:600;line-height:1.5em;text-align:center}@supports (-ms-accelerator:true){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@-moz-document url-prefix(){.swal2-close:focus{outline:2px solid rgba(50,100,150,.4)}}.swal2-icon{position:relative;box-sizing:content-box;justify-content:center;width:5em;height:5em;margin:1.25em auto 1.875em;zoom:normal;border:.25em solid transparent;border-radius:50%;line-height:5em;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.swal2-icon::before{display:flex;align-items:center;height:92%;font-size:3.75em}.swal2-icon.swal2-error{border-color:#f27474}.swal2-icon.swal2-error .swal2-x-mark{position:relative;flex-grow:1}.swal2-icon.swal2-error [class^=swal2-x-mark-line]{display:block;position:absolute;top:2.3125em;width:2.9375em;height:.3125em;border-radius:.125em;background-color:#f27474}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;-webkit-transform:rotate(45deg);transform:rotate(45deg)}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-icon.swal2-warning{border-color:#facea8;color:#f8bb86}.swal2-icon.swal2-warning::before{content:"!"}.swal2-icon.swal2-info{border-color:#9de0f6;color:#3fc3ee}.swal2-icon.swal2-info::before{content:"i"}.swal2-icon.swal2-question{border-color:#c9dae1;color:#87adbd}.swal2-icon.swal2-question::before{content:"?"}.swal2-icon.swal2-question.swal2-arabic-question-mark::before{content:"؟"}.swal2-icon.swal2-success{border-color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-circular-line]{position:absolute;width:3.75em;height:7.5em;-webkit-transform:rotate(45deg);transform:rotate(45deg);border-radius:50%}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=left]{top:-.4375em;left:-2.0635em;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:3.75em 3.75em;transform-origin:3.75em 3.75em;border-radius:7.5em 0 0 7.5em}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=right]{top:-.6875em;left:1.875em;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:0 3.75em;transform-origin:0 3.75em;border-radius:0 7.5em 7.5em 0}.swal2-icon.swal2-success .swal2-success-ring{position:absolute;z-index:2;top:-.25em;left:-.25em;box-sizing:content-box;width:100%;height:100%;border:.25em solid rgba(165,220,134,.3);border-radius:50%}.swal2-icon.swal2-success .swal2-success-fix{position:absolute;z-index:1;top:.5em;left:1.625em;width:.4375em;height:5.625em;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-icon.swal2-success [class^=swal2-success-line]{display:block;position:absolute;z-index:2;height:.3125em;border-radius:.125em;background-color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-line][class$=tip]{top:2.875em;left:.875em;width:1.5625em;-webkit-transform:rotate(45deg);transform:rotate(45deg)}.swal2-icon.swal2-success [class^=swal2-success-line][class$=long]{top:2.375em;right:.5em;width:2.9375em;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-progress-steps{align-items:center;margin:0 0 1.25em;padding:0;background:inherit;font-weight:600}.swal2-progress-steps li{display:inline-block;position:relative}.swal2-progress-steps .swal2-progress-step{z-index:20;width:2em;height:2em;border-radius:2em;background:#3085d6;color:#fff;line-height:2em;text-align:center}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#3085d6}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:#add8e6;color:#fff}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:#add8e6}.swal2-progress-steps .swal2-progress-step-line{z-index:10;width:2.5em;height:.4em;margin:0 -1px;background:#3085d6}[class^=swal2]{-webkit-tap-highlight-color:transparent}.swal2-show{-webkit-animation:swal2-show .3s;animation:swal2-show .3s}.swal2-show.swal2-noanimation{-webkit-animation:none;animation:none}.swal2-hide{-webkit-animation:swal2-hide .15s forwards;animation:swal2-hide .15s forwards}.swal2-hide.swal2-noanimation{-webkit-animation:none;animation:none}.swal2-rtl .swal2-close{right:auto;left:0}.swal2-animate-success-icon .swal2-success-line-tip{-webkit-animation:swal2-animate-success-line-tip .75s;animation:swal2-animate-success-line-tip .75s}.swal2-animate-success-icon .swal2-success-line-long{-webkit-animation:swal2-animate-success-line-long .75s;animation:swal2-animate-success-line-long .75s}.swal2-animate-success-icon .swal2-success-circular-line-right{-webkit-animation:swal2-rotate-success-circular-line 4.25s ease-in;animation:swal2-rotate-success-circular-line 4.25s ease-in}.swal2-animate-error-icon{-webkit-animation:swal2-animate-error-icon .5s;animation:swal2-animate-error-icon .5s}.swal2-animate-error-icon .swal2-x-mark{-webkit-animation:swal2-animate-error-x-mark .5s;animation:swal2-animate-error-x-mark .5s}@-webkit-keyframes swal2-rotate-loading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes swal2-rotate-loading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@media print{body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow-y:scroll!important}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown) .swal2-container{position:static!important}}</style><script async="" src="./axios中文文档_axios中文网 _ axios_files/modules.6707e94afd136d068134.js.下载" charset="utf-8"></script><style type="text/css">iframe#_hjRemoteVarsFrame {display: none !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important;}</style></head><body><a title="Real Time Web Analytics" href="http://clicky.com/101192693" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/badge.gif" border="0"></a>
<script>var clicky_site_ids = clicky_site_ids || []; clicky_site_ids.push(101192693);</script>
<script async="" src="./axios中文文档_axios中文网 _ axios_files/js"></script>






  <div id="container">
    <header id="header" class="wrapper">
  <div id="header-inner" class="inner">
    <h1 id="logo-wrap">
      <a href="http://www.axios-js.com/zh-cn/" id="logo">axios</a>
    </h1>
    <nav id="main-nav">
      <a href="http://www.axios-js.com/zh-cn/docs/" class="main-nav-link">文档</a><a href="http://www.axios-js.com/zh-cn/blogs/" class="main-nav-link">博客</a>
      <a href="https://github.com/" target="_blank" rel="noopener" class="main-nav-link"><i class="fa fa-github-alt"></i></a>
      <div id="search-input-wrap">
        <div id="search-input-icon">
          <i class="fa fa-search"></i>
        </div>
        <input type="search" id="search-input" placeholder="Search...">
      </div>
    </nav>
    <div id="lang-select-wrap">
      <label id="lang-select-label"><i class="fa fa-globe"></i><span>简体中文</span></label>
      <select id="lang-select" data-canonical="docs/index.html">
        
          <option value="en">undefined</option>
        
          <option value="zh-cn" selected="">简体中文</option>
        
      </select>
    </div>
    <a id="mobile-nav-toggle">
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
    </a>
  </div>
</header>

    <div id="content-wrap">
  <div id="content" class="wrapper">
    <div id="content-inner">
      <article class="article-container" itemscope="" itemtype="http://schema.org/Article">
        <div class="article-inner">
          <div class="article">
            <div class="inner">
              <header class="article-header">
                <h1 class="article-title" itemprop="name">axios中文文档|axios中文网</h1>
                <a href="https://github.com/hexojs/site/edit/master/source/zh-cn/docs/index.md" target="_blank" rel="noopener" class="article-edit-link" title="改进本文"></a>
              </header>
              <div class="article-content" itemprop="articleBody">
                <p class="vultr-desc">
                  本站由axios爱好者共建，部署在vultr vps上，推荐使用vultr!价格实惠，实力雄厚。
                  最近新注册用户充值$25,可额外获赠$50,搭建博客必备。
                  <a href="https://www.vultr.com/?ref=7865726-4F" target="_blank" rel="noopener">前往注册</a>
                </p>
                <a href="https://www.vultr.com/?ref=7865726-4F" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/banner_1_nrndlt.png" width="728" height="90"></a>
                <p>欢迎使用 axios，本文档将帮助您快速上手。(troubleshooting.html) 中的解答，</p>
<h2 id="什么是-axios？" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E4%BB%80%E4%B9%88%E6%98%AF-axios%EF%BC%9F" class="headerlink" title="什么是 axios？"></a>什么是 axios？<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E4%BB%80%E4%B9%88%E6%98%AF-axios%EF%BC%9F" aria-hidden="true"></a></h2><p>Axios 是一个基于 promise 的 HTTP 库，可以用在浏览器和 node.js 中。</p>
<h1 id="axios" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios" class="headerlink" title="axios"></a>axios<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios" aria-hidden="true"></a></h1><p><a href="https://www.npmjs.org/package/axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/axios.svg" alt="npm version"></a><br><a href="https://travis-ci.org/axios/axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/axios(1).svg" alt="build status"></a><br><a href="https://coveralls.io/r/mzabriskie/axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/axios(2).svg" alt="code coverage"></a><br><a href="http://npm-stat.com/charts.html?package=axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/axios(3).svg" alt="npm downloads"></a><br><a href="https://gitter.im/mzabriskie/axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/axios(4).svg" alt="gitter chat"></a><br><a href="https://www.codetriage.com/axios/axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/users.svg" alt="code helpers"></a></p>
<p>Axios 是一个基于 promise 的 HTTP 库，可以用在浏览器和 node.js 中。 </p>
<h2 id="特性" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E7%89%B9%E6%80%A7" class="headerlink" title="特性"></a>特性<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E7%89%B9%E6%80%A7" aria-hidden="true"></a></h2><ul>
<li>从浏览器中创建 <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest" target="_blank" rel="noopener">XMLHttpRequests</a></li>
<li>从 node.js 创建 <a href="http://nodejs.org/api/http.html" target="_blank" rel="noopener">http</a> 请求</li>
<li>支持 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" target="_blank" rel="noopener">Promise</a> API</li>
<li>拦截请求和响应</li>
<li>转换请求数据和响应数据</li>
<li>取消请求</li>
<li>自动转换 JSON 数据</li>
<li>客户端支持防御 <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery" target="_blank" rel="noopener">XSRF</a></li>
</ul>
<h2 id="浏览器支持" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%94%AF%E6%8C%81" class="headerlink" title="浏览器支持"></a>浏览器支持<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%94%AF%E6%8C%81" aria-hidden="true"></a></h2><table>
<thead>
<tr>
<th><img src="./axios中文文档_axios中文网 _ axios_files/chrome_48x48.png" alt="Chrome"></th>
<th><img src="./axios中文文档_axios中文网 _ axios_files/firefox_48x48.png" alt="Firefox"></th>
<th><img src="./axios中文文档_axios中文网 _ axios_files/safari_48x48.png" alt="Safari"></th>
<th><img src="./axios中文文档_axios中文网 _ axios_files/opera_48x48.png" alt="Opera"></th>
<th><img src="./axios中文文档_axios中文网 _ axios_files/edge_48x48.png" alt="Edge"></th>
<th><img src="./axios中文文档_axios中文网 _ axios_files/internet-explorer_9-11_48x48.png" alt="IE"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Latest ✔</td>
<td>Latest ✔</td>
<td>Latest ✔</td>
<td>Latest ✔</td>
<td>Latest ✔</td>
<td>8+ ✔</td>
<td></td>
</tr>
</tbody>
</table>
<p><a href="https://saucelabs.com/u/axios" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/axios(5).svg" alt="Browser Matrix"></a></p>
<!-- <a href="https://mobile.yangkeduo.com/app.html?use_reload=1&launch_url=duo_coupon_landing.html%3Fgoods_id%3D66855225823%26pid%3D10429761_141340817%26cpsSign%3DCC_200520_10429761_141340817_e02dc0ce5b38190bdfd63cbda354d206%26duoduo_type%3D2&campaign=ddjb&cid=launch_dl_force_" target="_blank" rel="noopener">
  <img width="300" src="https://res.cloudinary.com/dq9x329zv/image/upload/v1589976054/youdontknowjs_rrotmn.jpg" />
</a> -->
<p><a href="https://mobile.yangkeduo.com/app.html?use_reload=1&amp;launch_url=duo_coupon_landing.html%3Fgoods_id%3D46139472338%26pid%3D10429761_143717296%26cpsSign%3DCC_200607_10429761_143717296_76438071fc40f230ff288407e4bf495d%26duoduo_type%3D2&amp;campaign=ddjb&amp;cid=launch_dl_force_" target="_blank" rel="noopener"><br>  <img width="300" src="./axios中文文档_axios中文网 _ axios_files/69173465-4b00-4f42-ab61-f73891a130b4.jpg"><br></a></p>
<h2 id="安装" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%AE%89%E8%A3%85" class="headerlink" title="安装"></a>安装<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%AE%89%E8%A3%85" aria-hidden="true"></a></h2><p>使用 npm: </p>
<figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">$ npm install axios</span><br></pre></td></tr></tbody></table></figure>
<p>使用 bower: </p>
<figure class="highlight bash"><table><tbody><tr><td class="code"><pre><span class="line">$ bower install axios</span><br></pre></td></tr></tbody></table></figure>
<p>使用 cdn: </p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://unpkg.com/axios/dist/axios.min.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></tbody></table></figure>
<h2 id="案例" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E6%A1%88%E4%BE%8B" class="headerlink" title="案例"></a>案例<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E6%A1%88%E4%BE%8B" aria-hidden="true"></a></h2><p>执行 <code>GET</code> 请求 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// 为给定 ID 的 user 创建请求</span></span><br><span class="line">axios.get(<span class="string">'/user?ID=12345'</span>)</span><br><span class="line">  .then(<span class="function"><span class="keyword">function</span> (<span class="params">response</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(response);</span><br><span class="line">  })</span><br><span class="line">  .catch(<span class="function"><span class="keyword">function</span> (<span class="params">error</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(error);</span><br><span class="line">  });</span><br><span class="line"></span><br><span class="line"><span class="comment">// 上面的请求也可以这样做</span></span><br><span class="line">axios.get(<span class="string">'/user'</span>, {</span><br><span class="line">    params: {</span><br><span class="line">      ID: <span class="number">12345</span></span><br><span class="line">    }</span><br><span class="line">  })</span><br><span class="line">  .then(<span class="function"><span class="keyword">function</span> (<span class="params">response</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(response);</span><br><span class="line">  })</span><br><span class="line">  .catch(<span class="function"><span class="keyword">function</span> (<span class="params">error</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(error);</span><br><span class="line">  });</span><br></pre></td></tr></tbody></table></figure>
<p>执行 <code>POST</code> 请求 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">axios.post(<span class="string">'/user'</span>, {</span><br><span class="line">    firstName: <span class="string">'Fred'</span>,</span><br><span class="line">    lastName: <span class="string">'Flintstone'</span></span><br><span class="line">  })</span><br><span class="line">  .then(<span class="function"><span class="keyword">function</span> (<span class="params">response</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(response);</span><br><span class="line">  })</span><br><span class="line">  .catch(<span class="function"><span class="keyword">function</span> (<span class="params">error</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(error);</span><br><span class="line">  });</span><br></pre></td></tr></tbody></table></figure>
<p>执行多个并发请求 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getUserAccount</span>(<span class="params"></span>) </span>{</span><br><span class="line">  <span class="keyword">return</span> axios.get(<span class="string">'/user/12345'</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getUserPermissions</span>(<span class="params"></span>) </span>{</span><br><span class="line">  <span class="keyword">return</span> axios.get(<span class="string">'/user/12345/permissions'</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">axios.all([getUserAccount(), getUserPermissions()])</span><br><span class="line">  .then(axios.spread(<span class="function"><span class="keyword">function</span> (<span class="params">acct, perms</span>) </span>{</span><br><span class="line">    <span class="comment">// 两个请求现在都执行完成</span></span><br><span class="line">  }));</span><br></pre></td></tr></tbody></table></figure>
<h2 id="axios-API" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-API" class="headerlink" title="axios API"></a>axios API<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-API" aria-hidden="true"></a></h2><p>可以通过向 <code>axios</code> 传递相关配置来创建请求</p>
<h5 id="axios-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-config" class="headerlink" title="axios(config)"></a>axios(config)<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-config" aria-hidden="true"></a></h5><figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// 发送 POST 请求</span></span><br><span class="line">axios({</span><br><span class="line">  method: <span class="string">'post'</span>,</span><br><span class="line">  url: <span class="string">'/user/12345'</span>,</span><br><span class="line">  data: {</span><br><span class="line">    firstName: <span class="string">'Fred'</span>,</span><br><span class="line">    lastName: <span class="string">'Flintstone'</span></span><br><span class="line">  }</span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// 获取远端图片</span></span><br><span class="line">axios({</span><br><span class="line">  method:<span class="string">'get'</span>,</span><br><span class="line">  url:<span class="string">'http://bit.ly/2mTM3nY'</span>,</span><br><span class="line">  responseType:<span class="string">'stream'</span></span><br><span class="line">})</span><br><span class="line">  .then(<span class="function"><span class="keyword">function</span>(<span class="params">response</span>) </span>{</span><br><span class="line">  response.data.pipe(fs.createWriteStream(<span class="string">'ada_lovelace.jpg'</span>))</span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure>
<h5 id="axios-url-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-url-config" class="headerlink" title="axios(url[, config])"></a>axios(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-url-config" aria-hidden="true"></a></h5><figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// 发送 GET 请求（默认的方法）</span></span><br><span class="line">axios(<span class="string">'/user/12345'</span>);</span><br></pre></td></tr></tbody></table></figure>
<h3 id="请求方法的别名" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95%E7%9A%84%E5%88%AB%E5%90%8D" class="headerlink" title="请求方法的别名"></a>请求方法的别名<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95%E7%9A%84%E5%88%AB%E5%90%8D" aria-hidden="true"></a></h3><p>为方便起见，为所有支持的请求方法提供了别名 </p>
<h5 id="axios-request-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-request-config" class="headerlink" title="axios.request(config)"></a>axios.request(config)<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-request-config" aria-hidden="true"></a></h5><h5 id="axios-get-url-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-get-url-config" class="headerlink" title="axios.get(url[, config])"></a>axios.get(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-get-url-config" aria-hidden="true"></a></h5><h5 id="axios-delete-url-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-delete-url-config" class="headerlink" title="axios.delete(url[, config])"></a>axios.delete(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-delete-url-config" aria-hidden="true"></a></h5><h5 id="axios-head-url-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-head-url-config" class="headerlink" title="axios.head(url[, config])"></a>axios.head(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-head-url-config" aria-hidden="true"></a></h5><h5 id="axios-options-url-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-options-url-config" class="headerlink" title="axios.options(url[, config])"></a>axios.options(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-options-url-config" aria-hidden="true"></a></h5><h5 id="axios-post-url-data-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-post-url-data-config" class="headerlink" title="axios.post(url[, data[, config]])"></a>axios.post(url[, data[, config]])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-post-url-data-config" aria-hidden="true"></a></h5><h5 id="axios-put-url-data-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-put-url-data-config" class="headerlink" title="axios.put(url[, data[, config]])"></a>axios.put(url[, data[, config]])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-put-url-data-config" aria-hidden="true"></a></h5><h5 id="axios-patch-url-data-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-patch-url-data-config" class="headerlink" title="axios.patch(url[, data[, config]])"></a>axios.patch(url[, data[, config]])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-patch-url-data-config" aria-hidden="true"></a></h5><h6 id="注意" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E6%B3%A8%E6%84%8F" class="headerlink" title="注意"></a>注意<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E6%B3%A8%E6%84%8F" aria-hidden="true"></a></h6><p>在使用别名方法时， <code>url</code>、<code>method</code>、<code>data</code> 这些属性都不必在配置中指定。 </p>
<h3 id="并发" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%B9%B6%E5%8F%91" class="headerlink" title="并发"></a>并发<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%B9%B6%E5%8F%91" aria-hidden="true"></a></h3><p>处理并发请求的助手函数 </p>
<h5 id="axios-all-iterable" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-all-iterable" class="headerlink" title="axios.all(iterable)"></a>axios.all(iterable)<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-all-iterable" aria-hidden="true"></a></h5><h5 id="axios-spread-callback" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-spread-callback" class="headerlink" title="axios.spread(callback)"></a>axios.spread(callback)<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-spread-callback" aria-hidden="true"></a></h5><h3 id="创建实例" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%88%9B%E5%BB%BA%E5%AE%9E%E4%BE%8B" class="headerlink" title="创建实例"></a>创建实例<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%88%9B%E5%BB%BA%E5%AE%9E%E4%BE%8B" aria-hidden="true"></a></h3><p>可以使用自定义配置新建一个 axios 实例 </p>
<h5 id="axios-create-config" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-create-config" class="headerlink" title="axios.create([config])"></a>axios.create([config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-create-config" aria-hidden="true"></a></h5><figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> instance = axios.create({</span><br><span class="line">  baseURL: <span class="string">'https://some-domain.com/api/'</span>,</span><br><span class="line">  timeout: <span class="number">1000</span>,</span><br><span class="line">  headers: {<span class="string">'X-Custom-Header'</span>: <span class="string">'foobar'</span>}</span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure>
<h3 id="实例方法" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95" class="headerlink" title="实例方法"></a>实例方法<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95" aria-hidden="true"></a></h3><p>以下是可用的实例方法。指定的配置将与实例的配置合并。</p>
<h5 id="axios-request-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-request-config-1" class="headerlink" title="axios#request(config)"></a>axios#request(config)<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-request-config-1" aria-hidden="true"></a></h5><h5 id="axios-get-url-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-get-url-config-1" class="headerlink" title="axios#get(url[, config])"></a>axios#get(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-get-url-config-1" aria-hidden="true"></a></h5><h5 id="axios-delete-url-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-delete-url-config-1" class="headerlink" title="axios#delete(url[, config])"></a>axios#delete(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-delete-url-config-1" aria-hidden="true"></a></h5><h5 id="axios-head-url-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-head-url-config-1" class="headerlink" title="axios#head(url[, config])"></a>axios#head(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-head-url-config-1" aria-hidden="true"></a></h5><h5 id="axios-options-url-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-options-url-config-1" class="headerlink" title="axios#options(url[, config])"></a>axios#options(url[, config])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-options-url-config-1" aria-hidden="true"></a></h5><h5 id="axios-post-url-data-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-post-url-data-config-1" class="headerlink" title="axios#post(url[, data[, config]])"></a>axios#post(url[, data[, config]])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-post-url-data-config-1" aria-hidden="true"></a></h5><h5 id="axios-put-url-data-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-put-url-data-config-1" class="headerlink" title="axios#put(url[, data[, config]])"></a>axios#put(url[, data[, config]])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-put-url-data-config-1" aria-hidden="true"></a></h5><h5 id="axios-patch-url-data-config-1" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#axios-patch-url-data-config-1" class="headerlink" title="axios#patch(url[, data[, config]])"></a>axios#patch(url[, data[, config]])<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#axios-patch-url-data-config-1" aria-hidden="true"></a></h5><h2 id="请求配置" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E8%AF%B7%E6%B1%82%E9%85%8D%E7%BD%AE" class="headerlink" title="请求配置"></a>请求配置<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E8%AF%B7%E6%B1%82%E9%85%8D%E7%BD%AE" aria-hidden="true"></a></h2><p>这些是创建请求时可以用的配置选项。只有 <code>url</code> 是必需的。如果没有指定 <code>method</code>，请求将默认使用 <code>get</code> 方法。 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">{</span><br><span class="line">   <span class="comment">// `url` 是用于请求的服务器 URL</span></span><br><span class="line">  url: <span class="string">'/user'</span>,</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `method` 是创建请求时使用的方法</span></span><br><span class="line">  method: <span class="string">'get'</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// `baseURL` 将自动加在 `url` 前面，除非 `url` 是一个绝对 URL。</span></span><br><span class="line">  <span class="comment">// 它可以通过设置一个 `baseURL` 便于为 axios 实例的方法传递相对 URL</span></span><br><span class="line">  baseURL: <span class="string">'https://some-domain.com/api/'</span>,</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `transformRequest` 允许在向服务器发送前，修改请求数据</span></span><br><span class="line">  <span class="comment">// 只能用在 'PUT', 'POST' 和 'PATCH' 这几个请求方法</span></span><br><span class="line">  <span class="comment">// 后面数组中的函数必须返回一个字符串，或 ArrayBuffer，或 Stream</span></span><br><span class="line">  transformRequest: [<span class="function"><span class="keyword">function</span> (<span class="params">data, headers</span>) </span>{</span><br><span class="line">    <span class="comment">// 对 data 进行任意转换处理</span></span><br><span class="line">    <span class="keyword">return</span> data;</span><br><span class="line">  }],</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `transformResponse` 在传递给 then/catch 前，允许修改响应数据</span></span><br><span class="line">  transformResponse: [<span class="function"><span class="keyword">function</span> (<span class="params">data</span>) </span>{</span><br><span class="line">    <span class="comment">// 对 data 进行任意转换处理</span></span><br><span class="line">    <span class="keyword">return</span> data;</span><br><span class="line">  }],</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `headers` 是即将被发送的自定义请求头</span></span><br><span class="line">  headers: {<span class="string">'X-Requested-With'</span>: <span class="string">'XMLHttpRequest'</span>},</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `params` 是即将与请求一起发送的 URL 参数</span></span><br><span class="line">  <span class="comment">// 必须是一个无格式对象(plain object)或 URLSearchParams 对象</span></span><br><span class="line">  params: {</span><br><span class="line">    ID: <span class="number">12345</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">   <span class="comment">// `paramsSerializer` 是一个负责 `params` 序列化的函数</span></span><br><span class="line">  <span class="comment">// (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)</span></span><br><span class="line">  paramsSerializer: <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>{</span><br><span class="line">    <span class="keyword">return</span> Qs.stringify(params, {<span class="attr">arrayFormat</span>: <span class="string">'brackets'</span>})</span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `data` 是作为请求主体被发送的数据</span></span><br><span class="line">  <span class="comment">// 只适用于这些请求方法 'PUT', 'POST', 和 'PATCH'</span></span><br><span class="line">  <span class="comment">// 在没有设置 `transformRequest` 时，必须是以下类型之一：</span></span><br><span class="line">  <span class="comment">// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams</span></span><br><span class="line">  <span class="comment">// - 浏览器专属：FormData, File, Blob</span></span><br><span class="line">  <span class="comment">// - Node 专属： Stream</span></span><br><span class="line">  data: {</span><br><span class="line">    firstName: <span class="string">'Fred'</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `timeout` 指定请求超时的毫秒数(0 表示无超时时间)</span></span><br><span class="line">  <span class="comment">// 如果请求话费了超过 `timeout` 的时间，请求将被中断</span></span><br><span class="line">  timeout: <span class="number">1000</span>,</span><br><span class="line"></span><br><span class="line">   <span class="comment">// `withCredentials` 表示跨域请求时是否需要使用凭证</span></span><br><span class="line">  withCredentials: <span class="literal">false</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// `adapter` 允许自定义处理请求，以使测试更轻松</span></span><br><span class="line">  <span class="comment">// 返回一个 promise 并应用一个有效的响应 (查阅 [response docs](#response-api)).</span></span><br><span class="line">  adapter: <span class="function"><span class="keyword">function</span> (<span class="params">config</span>) </span>{</span><br><span class="line">    <span class="comment">/* ... */</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line"> <span class="comment">// `auth` 表示应该使用 HTTP 基础验证，并提供凭据</span></span><br><span class="line">  <span class="comment">// 这将设置一个 `Authorization` 头，覆写掉现有的任意使用 `headers` 设置的自定义 `Authorization`头</span></span><br><span class="line">  auth: {</span><br><span class="line">    username: <span class="string">'janedoe'</span>,</span><br><span class="line">    password: <span class="string">'s00pers3cret'</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">   <span class="comment">// `responseType` 表示服务器响应的数据类型，可以是 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'</span></span><br><span class="line">  responseType: <span class="string">'json'</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// `responseEncoding` indicates encoding to use for decoding responses</span></span><br><span class="line">  <span class="comment">// Note: Ignored for `responseType` of 'stream' or client-side requests</span></span><br><span class="line">  responseEncoding: <span class="string">'utf8'</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">   <span class="comment">// `xsrfCookieName` 是用作 xsrf token 的值的cookie的名称</span></span><br><span class="line">  xsrfCookieName: <span class="string">'XSRF-TOKEN'</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// `xsrfHeaderName` is the name of the http header that carries the xsrf token value</span></span><br><span class="line">  xsrfHeaderName: <span class="string">'X-XSRF-TOKEN'</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">   <span class="comment">// `onUploadProgress` 允许为上传处理进度事件</span></span><br><span class="line">  onUploadProgress: <span class="function"><span class="keyword">function</span> (<span class="params">progressEvent</span>) </span>{</span><br><span class="line">    <span class="comment">// Do whatever you want with the native progress event</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `onDownloadProgress` 允许为下载处理进度事件</span></span><br><span class="line">  onDownloadProgress: <span class="function"><span class="keyword">function</span> (<span class="params">progressEvent</span>) </span>{</span><br><span class="line">    <span class="comment">// 对原生进度事件的处理</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">   <span class="comment">// `maxContentLength` 定义允许的响应内容的最大尺寸</span></span><br><span class="line">  maxContentLength: <span class="number">2000</span>,</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `validateStatus` 定义对于给定的HTTP 响应状态码是 resolve 或 reject  promise 。如果 `validateStatus` 返回 `true` (或者设置为 `null` 或 `undefined`)，promise 将被 resolve; 否则，promise 将被 rejecte</span></span><br><span class="line">  validateStatus: <span class="function"><span class="keyword">function</span> (<span class="params">status</span>) </span>{</span><br><span class="line">    <span class="keyword">return</span> status &gt;= <span class="number">200</span> &amp;&amp; status &lt; <span class="number">300</span>; <span class="comment">// default</span></span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `maxRedirects` 定义在 node.js 中 follow 的最大重定向数目</span></span><br><span class="line">  <span class="comment">// 如果设置为0，将不会 follow 任何重定向</span></span><br><span class="line">  maxRedirects: <span class="number">5</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// `socketPath` defines a UNIX Socket to be used in node.js.</span></span><br><span class="line">  <span class="comment">// e.g. '/var/run/docker.sock' to send requests to the docker daemon.</span></span><br><span class="line">  <span class="comment">// Only either `socketPath` or `proxy` can be specified.</span></span><br><span class="line">  <span class="comment">// If both are specified, `socketPath` is used.</span></span><br><span class="line">  socketPath: <span class="literal">null</span>, <span class="comment">// default</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// `httpAgent` 和 `httpsAgent` 分别在 node.js 中用于定义在执行 http 和 https 时使用的自定义代理。允许像这样配置选项：</span></span><br><span class="line">  <span class="comment">// `keepAlive` 默认没有启用</span></span><br><span class="line">  httpAgent: <span class="keyword">new</span> http.Agent({ <span class="attr">keepAlive</span>: <span class="literal">true</span> }),</span><br><span class="line">  httpsAgent: <span class="keyword">new</span> https.Agent({ <span class="attr">keepAlive</span>: <span class="literal">true</span> }),</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 'proxy' 定义代理服务器的主机名称和端口</span></span><br><span class="line">  <span class="comment">// `auth` 表示 HTTP 基础验证应当用于连接代理，并提供凭据</span></span><br><span class="line">  <span class="comment">// 这将会设置一个 `Proxy-Authorization` 头，覆写掉已有的通过使用 `header` 设置的自定义 `Proxy-Authorization` 头。</span></span><br><span class="line">  proxy: {</span><br><span class="line">    host: <span class="string">'127.0.0.1'</span>,</span><br><span class="line">    port: <span class="number">9000</span>,</span><br><span class="line">    auth: {</span><br><span class="line">      username: <span class="string">'mikeymike'</span>,</span><br><span class="line">      password: <span class="string">'rapunz3l'</span></span><br><span class="line">    }</span><br><span class="line">  },</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `cancelToken` 指定用于取消请求的 cancel token</span></span><br><span class="line">  <span class="comment">// （查看后面的 Cancellation 这节了解更多）</span></span><br><span class="line">  cancelToken: <span class="keyword">new</span> CancelToken(<span class="function"><span class="keyword">function</span> (<span class="params">cancel</span>) </span>{</span><br><span class="line">  })</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="响应结构" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%93%8D%E5%BA%94%E7%BB%93%E6%9E%84" class="headerlink" title="响应结构"></a>响应结构<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%93%8D%E5%BA%94%E7%BB%93%E6%9E%84" aria-hidden="true"></a></h2><p>某个请求的响应包含以下信息 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">{</span><br><span class="line">  <span class="comment">// `data` 由服务器提供的响应</span></span><br><span class="line">  data: {},</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `status` 来自服务器响应的 HTTP 状态码</span></span><br><span class="line">  status: <span class="number">200</span>,</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `statusText` 来自服务器响应的 HTTP 状态信息</span></span><br><span class="line">  statusText: <span class="string">'OK'</span>,</span><br><span class="line"></span><br><span class="line">  <span class="comment">// `headers` 服务器响应的头</span></span><br><span class="line">  headers: {},</span><br><span class="line"></span><br><span class="line">   <span class="comment">// `config` 是为请求提供的配置信息</span></span><br><span class="line">  config: {},</span><br><span class="line"> <span class="comment">// 'request'</span></span><br><span class="line">  <span class="comment">// `request` is the request that generated this response</span></span><br><span class="line">  <span class="comment">// It is the last ClientRequest instance in node.js (in redirects)</span></span><br><span class="line">  <span class="comment">// and an XMLHttpRequest instance the browser</span></span><br><span class="line">  request: {}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>使用 <code>then</code> 时，你将接收下面这样的响应 :</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">axios.get(<span class="string">'/user/12345'</span>)</span><br><span class="line">  .then(<span class="function"><span class="keyword">function</span>(<span class="params">response</span>) </span>{</span><br><span class="line">    <span class="built_in">console</span>.log(response.data);</span><br><span class="line">    <span class="built_in">console</span>.log(response.status);</span><br><span class="line">    <span class="built_in">console</span>.log(response.statusText);</span><br><span class="line">    <span class="built_in">console</span>.log(response.headers);</span><br><span class="line">    <span class="built_in">console</span>.log(response.config);</span><br><span class="line">  });</span><br></pre></td></tr></tbody></table></figure>
<p>在使用 <code>catch</code> 时，或传递 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then" target="_blank" rel="noopener">rejection callback</a> 作为 <code>then</code> 的第二个参数时，响应可以通过 <code>error</code> 对象可被使用，正如在<a href="https://www.kancloud.cn/yunye/axios/234845#handling-errors" target="_blank" rel="noopener">错误处理</a>这一节所讲。 </p>
<h2 id="配置默认值" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E9%85%8D%E7%BD%AE%E9%BB%98%E8%AE%A4%E5%80%BC" class="headerlink" title="配置默认值"></a>配置默认值<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E9%85%8D%E7%BD%AE%E9%BB%98%E8%AE%A4%E5%80%BC" aria-hidden="true"></a></h2><p>你可以指定将被用在各个请求的配置默认值 </p>
<h3 id="全局的-axios-默认值" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%85%A8%E5%B1%80%E7%9A%84-axios-%E9%BB%98%E8%AE%A4%E5%80%BC" class="headerlink" title="全局的 axios 默认值"></a>全局的 axios 默认值<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%85%A8%E5%B1%80%E7%9A%84-axios-%E9%BB%98%E8%AE%A4%E5%80%BC" aria-hidden="true"></a></h3><figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">axios.defaults.baseURL = <span class="string">'https://api.example.com'</span>;</span><br><span class="line">axios.defaults.headers.common[<span class="string">'Authorization'</span>] = AUTH_TOKEN;</span><br><span class="line">axios.defaults.headers.post[<span class="string">'Content-Type'</span>] = <span class="string">'application/x-www-form-urlencoded'</span>;</span><br></pre></td></tr></tbody></table></figure>
<h3 id="自定义实例默认值" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AE%9E%E4%BE%8B%E9%BB%98%E8%AE%A4%E5%80%BC" class="headerlink" title="自定义实例默认值"></a>自定义实例默认值<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AE%9E%E4%BE%8B%E9%BB%98%E8%AE%A4%E5%80%BC" aria-hidden="true"></a></h3><figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// Set config defaults when creating the instance</span></span><br><span class="line"><span class="keyword">const</span> instance = axios.create({</span><br><span class="line">  baseURL: <span class="string">'https://api.example.com'</span></span><br><span class="line">});</span><br><span class="line"></span><br><span class="line"><span class="comment">// Alter defaults after instance has been created</span></span><br><span class="line">instance.defaults.headers.common[<span class="string">'Authorization'</span>] = AUTH_TOKEN;</span><br></pre></td></tr></tbody></table></figure>
<h3 id="配置的优先顺序" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E9%85%8D%E7%BD%AE%E7%9A%84%E4%BC%98%E5%85%88%E9%A1%BA%E5%BA%8F" class="headerlink" title="配置的优先顺序"></a>配置的优先顺序<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E9%85%8D%E7%BD%AE%E7%9A%84%E4%BC%98%E5%85%88%E9%A1%BA%E5%BA%8F" aria-hidden="true"></a></h3><p>配置会以一个优先顺序进行合并。这个顺序是：在 <code>lib/defaults.js</code> 找到的库的默认值，然后是实例的 <code>defaults</code> 属性，最后是请求的 <code>config</code> 参数。后者将优先于前者。这里是一个例子： </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// 使用由库提供的配置的默认值来创建实例</span></span><br><span class="line"><span class="comment">// 此时超时配置的默认值是 `0`</span></span><br><span class="line"><span class="keyword">var</span> instance = axios.create();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 覆写库的超时默认值</span></span><br><span class="line"><span class="comment">// 现在，在超时前，所有请求都会等待 2.5 秒</span></span><br><span class="line">instance.defaults.timeout = <span class="number">2500</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 为已知需要花费很长时间的请求覆写超时设置</span></span><br><span class="line">instance.get(<span class="string">'/longRequest'</span>, {</span><br><span class="line">  timeout: <span class="number">5000</span></span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure>
<h2 id="拦截器" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E6%8B%A6%E6%88%AA%E5%99%A8" class="headerlink" title="拦截器"></a>拦截器<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E6%8B%A6%E6%88%AA%E5%99%A8" aria-hidden="true"></a></h2><p>在请求或响应被 <code>then</code> 或 <code>catch</code> 处理前拦截它们。 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="comment">// 添加请求拦截器</span></span><br><span class="line">axios.interceptors.request.use(<span class="function"><span class="keyword">function</span> (<span class="params">config</span>) </span>{</span><br><span class="line">    <span class="comment">// 在发送请求之前做些什么</span></span><br><span class="line">    <span class="keyword">return</span> config;</span><br><span class="line">  }, <span class="function"><span class="keyword">function</span> (<span class="params">error</span>) </span>{</span><br><span class="line">    <span class="comment">// 对请求错误做些什么</span></span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Promise</span>.reject(error);</span><br><span class="line">  });</span><br><span class="line"></span><br><span class="line"><span class="comment">// 添加响应拦截器</span></span><br><span class="line">axios.interceptors.response.use(<span class="function"><span class="keyword">function</span> (<span class="params">response</span>) </span>{</span><br><span class="line">    <span class="comment">// 对响应数据做点什么</span></span><br><span class="line">    <span class="keyword">return</span> response;</span><br><span class="line">  }, <span class="function"><span class="keyword">function</span> (<span class="params">error</span>) </span>{</span><br><span class="line">    <span class="comment">// 对响应错误做点什么</span></span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Promise</span>.reject(error);</span><br><span class="line">  });</span><br></pre></td></tr></tbody></table></figure>
<p>如果你想在稍后移除拦截器，可以这样： </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> myInterceptor = axios.interceptors.request.use(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{<span class="comment">/*...*/</span>});</span><br><span class="line">axios.interceptors.request.eject(myInterceptor);</span><br></pre></td></tr></tbody></table></figure>
<p>可以为自定义 axios 实例添加拦截器 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> instance = axios.create();</span><br><span class="line">instance.interceptors.request.use(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{<span class="comment">/*...*/</span>});</span><br></pre></td></tr></tbody></table></figure>
<h2 id="错误处理" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86" class="headerlink" title="错误处理"></a>错误处理<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86" aria-hidden="true"></a></h2><figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">axios.get(<span class="string">'/user/12345'</span>)</span><br><span class="line">  .catch(<span class="function"><span class="keyword">function</span> (<span class="params">error</span>) </span>{</span><br><span class="line">    <span class="keyword">if</span> (error.response) {</span><br><span class="line">      <span class="comment">// The request was made and the server responded with a status code</span></span><br><span class="line">      <span class="comment">// that falls out of the range of 2xx</span></span><br><span class="line">      <span class="built_in">console</span>.log(error.response.data);</span><br><span class="line">      <span class="built_in">console</span>.log(error.response.status);</span><br><span class="line">      <span class="built_in">console</span>.log(error.response.headers);</span><br><span class="line">    } <span class="keyword">else</span> <span class="keyword">if</span> (error.request) {</span><br><span class="line">      <span class="comment">// The request was made but no response was received</span></span><br><span class="line">      <span class="comment">// `error.request` is an instance of XMLHttpRequest in the browser and an instance of</span></span><br><span class="line">      <span class="comment">// http.ClientRequest in node.js</span></span><br><span class="line">      <span class="built_in">console</span>.log(error.request);</span><br><span class="line">    } <span class="keyword">else</span> {</span><br><span class="line">      <span class="comment">// Something happened in setting up the request that triggered an Error</span></span><br><span class="line">      <span class="built_in">console</span>.log(<span class="string">'Error'</span>, error.message);</span><br><span class="line">    }</span><br><span class="line">    <span class="built_in">console</span>.log(error.config);</span><br><span class="line">  });</span><br></pre></td></tr></tbody></table></figure>
<p>Y可以使用 <code>validateStatus</code> 配置选项定义一个自定义 HTTP 状态码的错误范围。 </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line">axios.get(<span class="string">'/user/12345'</span>, {</span><br><span class="line">  validateStatus: <span class="function"><span class="keyword">function</span> (<span class="params">status</span>) </span>{</span><br><span class="line">    <span class="keyword">return</span> status &lt; <span class="number">500</span>; <span class="comment">// Reject only if the status code is greater than or equal to 500</span></span><br><span class="line">  }</span><br><span class="line">})</span><br></pre></td></tr></tbody></table></figure>
<h2 id="取消" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%8F%96%E6%B6%88" class="headerlink" title="取消"></a>取消<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%8F%96%E6%B6%88" aria-hidden="true"></a></h2><p>使用 <em>cancel token</em> 取消请求</p>
<blockquote>
<p>Axios 的 cancel token API 基于<a href="https://github.com/tc39/proposal-cancelable-promises" target="_blank" rel="noopener">cancelable promises proposal</a>，它还处于第一阶段。 </p>
</blockquote>
<p>可以使用 <code>CancelToken.source</code> 工厂方法创建 cancel token，像这样： </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> CancelToken = axios.CancelToken;</span><br><span class="line"><span class="keyword">const</span> source = CancelToken.source();</span><br><span class="line"></span><br><span class="line">axios.get(<span class="string">'/user/12345'</span>, {</span><br><span class="line">  cancelToken: source.token</span><br><span class="line">}).catch(<span class="function"><span class="keyword">function</span>(<span class="params">thrown</span>) </span>{</span><br><span class="line">  <span class="keyword">if</span> (axios.isCancel(thrown)) {</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'Request canceled'</span>, thrown.message);</span><br><span class="line">  } <span class="keyword">else</span> {</span><br><span class="line">     <span class="comment">// 处理错误</span></span><br><span class="line">  }</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line">axios.post(<span class="string">'/user/12345'</span>, {</span><br><span class="line">  name: <span class="string">'new name'</span></span><br><span class="line">}, {</span><br><span class="line">  cancelToken: source.token</span><br><span class="line">})</span><br><span class="line"></span><br><span class="line"><span class="comment">// 取消请求（message 参数是可选的）</span></span><br><span class="line">source.cancel(<span class="string">'Operation canceled by the user.'</span>);</span><br></pre></td></tr></tbody></table></figure>
<p>还可以通过传递一个 executor 函数到 <code>CancelToken</code> 的构造函数来创建 cancel token： </p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> CancelToken = axios.CancelToken;</span><br><span class="line"><span class="keyword">let</span> cancel;</span><br><span class="line"></span><br><span class="line">axios.get(<span class="string">'/user/12345'</span>, {</span><br><span class="line">  cancelToken: <span class="keyword">new</span> CancelToken(<span class="function"><span class="keyword">function</span> <span class="title">executor</span>(<span class="params">c</span>) </span>{</span><br><span class="line">    <span class="comment">// executor 函数接收一个 cancel 函数作为参数</span></span><br><span class="line">    cancel = c;</span><br><span class="line">  })</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line"><span class="comment">// cancel the request</span></span><br><span class="line">cancel();</span><br></pre></td></tr></tbody></table></figure>
<blockquote>
<p>注意: 可以使用同一个 cancel token 取消多个请求 </p>
</blockquote>
<h2 id="使用-application-x-www-form-urlencoded-format" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E4%BD%BF%E7%94%A8-application-x-www-form-urlencoded-format" class="headerlink" title="使用 application/x-www-form-urlencoded format"></a>使用 application/x-www-form-urlencoded format<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E4%BD%BF%E7%94%A8-application-x-www-form-urlencoded-format" aria-hidden="true"></a></h2><p>默认情况下，axios将JavaScript对象序列化为JSON。 要以application / x-www-form-urlencoded格式发送数据，您可以使用以下选项之一。</p>
<h3 id="浏览器" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E6%B5%8F%E8%A7%88%E5%99%A8" class="headerlink" title="浏览器"></a>浏览器<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E6%B5%8F%E8%A7%88%E5%99%A8" aria-hidden="true"></a></h3><p>在浏览器中，您可以使用URLSearchParams API，如下所示：</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> params = <span class="keyword">new</span> URLSearchParams();</span><br><span class="line">params.append(<span class="string">'param1'</span>, <span class="string">'value1'</span>);</span><br><span class="line">params.append(<span class="string">'param2'</span>, <span class="string">'value2'</span>);</span><br><span class="line">axios.post(<span class="string">'/foo'</span>, params);</span><br></pre></td></tr></tbody></table></figure>
<blockquote>
<p>请注意，所有浏览器都不支持URLSearchParams（请参阅caniuse.com），但可以使用polyfill（确保填充全局环境）。</p>
</blockquote>
<p>或者，您可以使用qs库编码数据：</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> qs = <span class="built_in">require</span>(<span class="string">'qs'</span>);</span><br><span class="line">axios.post(<span class="string">'/foo'</span>, qs.stringify({ <span class="string">'bar'</span>: <span class="number">123</span> }));</span><br></pre></td></tr></tbody></table></figure>
<p>或者以另一种方式（ES6），</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> qs <span class="keyword">from</span> <span class="string">'qs'</span>;</span><br><span class="line"><span class="keyword">const</span> data = { <span class="string">'bar'</span>: <span class="number">123</span> };</span><br><span class="line"><span class="keyword">const</span> options = {</span><br><span class="line">  method: <span class="string">'POST'</span>,</span><br><span class="line">  headers: { <span class="string">'content-type'</span>: <span class="string">'application/x-www-form-urlencoded'</span> },</span><br><span class="line">  data: qs.stringify(data),</span><br><span class="line">  url,</span><br><span class="line">};</span><br><span class="line">axios(options);</span><br></pre></td></tr></tbody></table></figure>
<h3 id="Node-js" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#Node-js" class="headerlink" title="Node.js"></a>Node.js<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#Node-js" aria-hidden="true"></a></h3><p>在node.js中，您可以使用querystring模块，如下所示：</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> querystring = <span class="built_in">require</span>(<span class="string">'querystring'</span>);</span><br><span class="line">axios.post(<span class="string">'http://something.com/'</span>, querystring.stringify({ <span class="attr">foo</span>: <span class="string">'bar'</span> }));</span><br></pre></td></tr></tbody></table></figure>
<p>您也可以使用qs库。</p>
<h2 id="Semver" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#Semver" class="headerlink" title="Semver"></a>Semver<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#Semver" aria-hidden="true"></a></h2><p>在axios达到1.0版本之前，破坏性更改将以新的次要版本发布。 例如0.5.1和0.5.4将具有相同的API，但0.6.0将具有重大变化。</p>
<h2 id="Promises" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#Promises" class="headerlink" title="Promises"></a>Promises<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#Promises" aria-hidden="true"></a></h2><p>axios 依赖原生的 ES6 Promise 实现而<a href="http://caniuse.com/promises" target="_blank" rel="noopener">被支持</a>. 如果你的环境不支持 ES6 Promise，你可以使用 <a href="https://github.com/jakearchibald/es6-promise" target="_blank" rel="noopener">polyfill</a>. </p>
<h2 id="TypeScript" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#TypeScript" class="headerlink" title="TypeScript"></a>TypeScript<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#TypeScript" aria-hidden="true"></a></h2><p>axios包括TypeScript定义。<br></p><figure class="highlight typescript"><table><tbody><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> axios <span class="keyword">from</span> <span class="string">'axios'</span>;</span><br><span class="line">axios.get(<span class="string">'/user?ID=12345'</span>);</span><br></pre></td></tr></tbody></table></figure><p></p>
<h2 id="资源" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E8%B5%84%E6%BA%90" class="headerlink" title="资源"></a>资源<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E8%B5%84%E6%BA%90" aria-hidden="true"></a></h2><ul>
<li><a href="https://github.com/axios/axios/blob/master/CHANGELOG.md" target="_blank" rel="noopener">Changelog</a></li>
<li><a href="https://github.com/axios/axios/blob/master/UPGRADE_GUIDE.md" target="_blank" rel="noopener">Upgrade Guide</a></li>
<li><a href="https://github.com/axios/axios/blob/master/ECOSYSTEM.md" target="_blank" rel="noopener">Ecosystem</a></li>
<li><a href="https://github.com/axios/axios/blob/master/CONTRIBUTING.md" target="_blank" rel="noopener">Contributing Guide</a></li>
<li><a href="https://github.com/axios/axios/blob/master/CODE_OF_CONDUCT.md" target="_blank" rel="noopener">Code of Conduct</a></li>
</ul>
<h2 id="Credits" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#Credits" class="headerlink" title="Credits"></a>Credits<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#Credits" aria-hidden="true"></a></h2><p>axios深受Angular提供的、\$http服务的启发。 最终，axios是为了在Angular之外使用而提供独立的类似\$http服的务。</p>
<h2 id="协议" class="article-heading"><a href="http://www.axios-js.com/zh-cn/docs/#%E5%8D%8F%E8%AE%AE" class="headerlink" title="协议"></a>协议<a class="article-anchor" href="http://www.axios-js.com/zh-cn/docs/#%E5%8D%8F%E8%AE%AE" aria-hidden="true"></a></h2><p>MIT</p>
<div class="recommand">以下课程十分推荐想往前端架构师方向精进的同学，月入5万的梦想总要有的！投资自己就是最好的投资！</div><div class="lessonlist"><div class="lession"><a href="https://t8.lagounews.com/FR17RsRBcHBD3" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/les01.jpeg" class="lesspic"></a></div><div class="lession"><a href="https://t7.lagounews.com/FR62RRRkcH772" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/les02.jpeg" class="lesspic"></a></div><div class="lession"><a href="https://t6.lagounews.com/FRCFRKRAcHE94" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/les03.jpeg" class="lesspic"></a></div><div class="lession"><a href="https://t8.lagounews.com/FRCARHRkcHF54" target="_blank" rel="noopener"><img src="./axios中文文档_axios中文网 _ axios_files/les04.jpeg" class="lesspic"></a></div></div>



              </div>
              <footer class="article-footer">
                <time class="article-footer-updated" datetime="2021-05-30T01:01:16.000Z" itemprop="dateModified">上次更新：2021-05-30</time>
                <a href="http://www.axios-js.com/zh-cn/docs/vue-axios.html" class="article-footer-next" title="vue-axios"><span>下一页</span><i class="fa fa-chevron-right"></i></a>
              </footer>
              
            </div>
          </div>
          <aside id="article-toc" role="navigation" class="">
            <div id="article-toc-inner">
              <strong class="sidebar-title">目录</strong>
              <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E4%BB%80%E4%B9%88%E6%98%AF-axios%EF%BC%9F"><span class="toc-text">什么是 axios？</span></a></li></ol><li class="toc-item toc-level-1"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios"><span class="toc-text">axios</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E7%89%B9%E6%80%A7"><span class="toc-text">特性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%94%AF%E6%8C%81"><span class="toc-text">浏览器支持</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%AE%89%E8%A3%85"><span class="toc-text">安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E6%A1%88%E4%BE%8B"><span class="toc-text">案例</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-API"><span class="toc-text">axios API</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-config"><span class="toc-text">axios(config)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-url-config"><span class="toc-text">axios(url[, config])</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95%E7%9A%84%E5%88%AB%E5%90%8D"><span class="toc-text">请求方法的别名</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-request-config"><span class="toc-text">axios.request(config)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-get-url-config"><span class="toc-text">axios.get(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-delete-url-config"><span class="toc-text">axios.delete(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-head-url-config"><span class="toc-text">axios.head(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-options-url-config"><span class="toc-text">axios.options(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-post-url-data-config"><span class="toc-text">axios.post(url[, data[, config]])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-put-url-data-config"><span class="toc-text">axios.put(url[, data[, config]])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-patch-url-data-config"><span class="toc-text">axios.patch(url[, data[, config]])</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E6%B3%A8%E6%84%8F"><span class="toc-text">注意</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%B9%B6%E5%8F%91"><span class="toc-text">并发</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-all-iterable"><span class="toc-text">axios.all(iterable)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-spread-callback"><span class="toc-text">axios.spread(callback)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%88%9B%E5%BB%BA%E5%AE%9E%E4%BE%8B"><span class="toc-text">创建实例</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-create-config"><span class="toc-text">axios.create([config])</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95"><span class="toc-text">实例方法</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-request-config-1"><span class="toc-text">axios#request(config)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-get-url-config-1"><span class="toc-text">axios#get(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-delete-url-config-1"><span class="toc-text">axios#delete(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-head-url-config-1"><span class="toc-text">axios#head(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-options-url-config-1"><span class="toc-text">axios#options(url[, config])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-post-url-data-config-1"><span class="toc-text">axios#post(url[, data[, config]])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-put-url-data-config-1"><span class="toc-text">axios#put(url[, data[, config]])</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#axios-patch-url-data-config-1"><span class="toc-text">axios#patch(url[, data[, config]])</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E8%AF%B7%E6%B1%82%E9%85%8D%E7%BD%AE"><span class="toc-text">请求配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%93%8D%E5%BA%94%E7%BB%93%E6%9E%84"><span class="toc-text">响应结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E9%85%8D%E7%BD%AE%E9%BB%98%E8%AE%A4%E5%80%BC"><span class="toc-text">配置默认值</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%85%A8%E5%B1%80%E7%9A%84-axios-%E9%BB%98%E8%AE%A4%E5%80%BC"><span class="toc-text">全局的 axios 默认值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AE%9E%E4%BE%8B%E9%BB%98%E8%AE%A4%E5%80%BC"><span class="toc-text">自定义实例默认值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E9%85%8D%E7%BD%AE%E7%9A%84%E4%BC%98%E5%85%88%E9%A1%BA%E5%BA%8F"><span class="toc-text">配置的优先顺序</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E6%8B%A6%E6%88%AA%E5%99%A8"><span class="toc-text">拦截器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86"><span class="toc-text">错误处理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%8F%96%E6%B6%88"><span class="toc-text">取消</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E4%BD%BF%E7%94%A8-application-x-www-form-urlencoded-format"><span class="toc-text">使用 application/x-www-form-urlencoded format</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E6%B5%8F%E8%A7%88%E5%99%A8"><span class="toc-text">浏览器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#Node-js"><span class="toc-text">Node.js</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#Semver"><span class="toc-text">Semver</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#Promises"><span class="toc-text">Promises</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#TypeScript"><span class="toc-text">TypeScript</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E8%B5%84%E6%BA%90"><span class="toc-text">资源</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#Credits"><span class="toc-text">Credits</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="http://www.axios-js.com/zh-cn/docs/#%E5%8D%8F%E8%AE%AE"><span class="toc-text">协议</span></a></li>
              <a href="http://www.axios-js.com/zh-cn/docs/#" id="article-toc-top">回到顶部</a>
            </div>
          </aside>
        </div>
      </article>
      <aside id="sidebar" role="navigation">
  <div class="inner">
    <strong class="sidebar-title">开始使用</strong><a href="http://www.axios-js.com/zh-cn/docs/index.html" class="sidebar-link current">概述</a><strong class="sidebar-title">框架整合</strong><a href="http://www.axios-js.com/zh-cn/docs/vue-axios.html" class="sidebar-link">vue-axios</a><a href="http://www.axios-js.com/zh-cn/docs/nuxtjs-axios.html" class="sidebar-link">nuxtjs-axios</a><a href="http://www.axios-js.com/zh-cn/docs/react-axios.html" class="sidebar-link">react-axios</a><strong class="sidebar-title">Plugins</strong><a href="http://www.axios-js.com/zh-cn/docs/axios-retry.html" class="sidebar-link">axios-retry</a><a href="http://www.axios-js.com/zh-cn/docs/vue-axios-plugin.html" class="sidebar-link">vue-axios-plugin</a>
  </div>
</aside>
    </div>
  </div>
</div>

    <footer id="footer" class="wrapper">
  <div class="inner">
    <div id="footer-copyright">
      © 2021 axios中文网<br>
      Documentation licensed under <a href="http://creativecommons.org/licenses/by/4.0/" target="_blank">CC BY 4.0</a>.
    </div>
    <div id="footer-links">
      <a href="https://twitter.com/" class="footer-link" target="_blank"><i class="fa fa-twitter"></i></a>
      <a href="https://github.com/" class="footer-link" target="_blank"><i class="fa fa-github-alt"></i></a>
    </div>
  </div>
</footer>

  </div>
  <div id="mobile-nav-dimmer"></div>
  <nav id="mobile-nav">
  <div id="mobile-nav-inner">
    <ul id="mobile-nav-list">
      <a href="http://www.axios-js.com/zh-cn/docs/" class="mobile-nav-link">文档</a><a href="http://www.axios-js.com/zh-cn/blogs/" class="mobile-nav-link">博客</a>
      <li class="mobile-nav-item">
        <a href="https://github.com/" class="mobile-nav-link" rel="external" target="_blank">GitHub</a>
      </li>
    </ul>
    
      <strong class="mobile-nav-title">开始使用</strong><a href="http://www.axios-js.com/zh-cn/docs/index.html" class="mobile-nav-link current">概述</a><strong class="mobile-nav-title">框架整合</strong><a href="http://www.axios-js.com/zh-cn/docs/vue-axios.html" class="mobile-nav-link">vue-axios</a><a href="http://www.axios-js.com/zh-cn/docs/nuxtjs-axios.html" class="mobile-nav-link">nuxtjs-axios</a><a href="http://www.axios-js.com/zh-cn/docs/react-axios.html" class="mobile-nav-link">react-axios</a><strong class="mobile-nav-title">Plugins</strong><a href="http://www.axios-js.com/zh-cn/docs/axios-retry.html" class="mobile-nav-link">axios-retry</a><a href="http://www.axios-js.com/zh-cn/docs/vue-axios-plugin.html" class="mobile-nav-link">vue-axios-plugin</a>
    
  </div>
  <div id="mobile-lang-select-wrap">
    <span id="mobile-lang-select-label"><i class="fa fa-globe"></i><span>简体中文</span></span>
    <select id="mobile-lang-select" data-canonical="docs/index.html">
      
        <option value="en">undefined</option>
      
        <option value="zh-cn" selected="">简体中文</option>
      
    </select>
  </div>
</nav>
  <!-- Scripts -->
<!-- build:js build/js/main.js -->

<script src="./axios中文文档_axios中文网 _ axios_files/lang_select.js.下载"></script>


<script src="./axios中文文档_axios中文网 _ axios_files/toc.js.下载"></script>


<script src="./axios中文文档_axios中文网 _ axios_files/mobile_nav.js.下载"></script>

<!-- endbuild -->

<!-- Algolia -->




<div class="popup-container">
  
<link rel="stylesheet" href="./axios中文文档_axios中文网 _ axios_files/pure-min.css">
<link rel="stylesheet" href="./axios中文文档_axios中文网 _ axios_files/sweetalert2.min.css">
<style>
    #magic-popup {
        color: #000;
        
    }
    .vultr-coupon {
        margin-top: 20px
    }
    .popup-container {
        visibility: hidden;
        position: relative
    }

    .coupon {
        font-size: 16px;
    }
    .desc {
        margin-top: 10px;
        color: #03a9f4;
        font-size: 16px;
    }
    .reason {
        position: absolute;
        bottom: 0;
        right: 10px;
        width: 100%;
        font-size: 12px;
        color: red
    }

    .red-packet {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    #magic-popup{
        height: 200px
    }

    .campaign-tip {
        font-size: 14px;
        letter-spacing: 0
    }
</style>
<div class="popup-container">
<div id="magic-popup" class="magic-popup">
    <div class="pure-g"> 
            <a href="https://mobile.yangkeduo.com/duo_gift.html?pid=10429761_157248162&amp;dis_t=1&amp;cpsSign=CR_200918_10429761_157248162_6209d398d516b504f8842b74926501c5&amp;duoduo_type=2" class="red-packet">
            <img width="150" src="./axios中文文档_axios中文网 _ axios_files/redpacket_n6cqu1.jpg">
            
            <span class="campaign-tip">拼多多新人专享红包！最高188元，限时领取！还有新人0元购，更多福利等你来拿~&gt;&gt;</span>
            </a>
    </div>

    <!-- >
    <div class="pure-g">
            <div class="pure-u-12-24">
              <a class="pure-button pure-button-primary coupon" href="http://bit.ly/2PpdaHG" target="_blank" rel="noopener" class="btn btn-default btn-md" role="button">virmach特价vps</a>
            </div>

            <div class="pure-u-12-24">
              <a class="pure-button pure-button-primary coupon" href="http://bit.ly/2NDPn4N" target="_blank" rel="noopener" class="btn btn-default btn-md" role="button">vultr新户送$100</a>
            </div>
                
    </div>
    <div class="desc">
    vps可用来搭建博客，学习Linux，搭建个人网盘，私人git，
    可以搭建ssr一键使用google,搜索资料更方便。以上支持支付宝付款。
    </div>

    <div class="reason">
        广告费用用于支持本站服务器费用，希望大家理解
    </div> 

    <-->

    
    
</div>
</div>
</div>
<script src="./axios中文文档_axios中文网 _ axios_files/jquery.min.js.下载"></script>
<script src="./axios中文文档_axios中文网 _ axios_files/sweetalert2.all.js.下载"></script>
<script src="./axios中文文档_axios中文网 _ axios_files/js.cookie.min.js.下载"></script>

<script type="text/javascript">
var result = Cookies.get('popuped');
if(result){

} else {
Cookies.set('popuped', '1', { expires: 7 })
// Swal.fire({
//   title: '<strong></strong>',
//   icon: 'info',
//   html: $('#magic-popup'),
//   focusConfirm: false,
//   confirmButtonText: '知道了'
// })
}


</script>






<script type="text/javascript" async="" src="./axios中文文档_axios中文网 _ axios_files/in.php"></script><iframe name="_hjRemoteVarsFrame" title="_hjRemoteVarsFrame" id="_hjRemoteVarsFrame" src="./axios中文文档_axios中文网 _ axios_files/box-25a418976ea02a6f393fbbe77cec94bb.html" style="display: none !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important;"></iframe></body></html>